package com.wangp.mywrite.coding;

import java.util.HashSet;
import java.util.Set;

/***
 * @author wangpeng
 * @since 2023-02-07  14:59
 */
public class LengthOfLongestSubstring {

    public int lengthOfLongestSubstring(String s) {
        if (s == null || s.length() == 0) {
            return 0;
        }
        int maxSize = 0, i = 0, j = 0;
        Set<Character> hashSet = new HashSet<>();
        while (i < s.length() && j < s.length()) {
            if (!hashSet.contains(s.charAt(j))) {
                hashSet.add(s.charAt(j++));
                maxSize = Math.max(maxSize, j - i);
            } else {
                hashSet.remove(s.charAt(i++));
            }
        }
        return maxSize;
    }

    public static void main(String[] args) {
        System.out.println(new LengthOfLongestSubstring().lengthOfLongestSubstring("dvadf"));
    }

}
